class Solution
{
public:
    int waysToMakeFair(vector<int> &nums)
    {
        int n = nums.size();
        int evenSum = 0;
        int oddSum = 0;
        for (int i = 0; i < n; ++i)
        {
            if (i & 1)
            {
                oddSum += nums[i];
            }
            else
            {
                evenSum += nums[i];
            }
        }

        int frontEvenSum = 0;
        int frontOddSum = 0;
        int backOddSum = 0;
        int backEvenSum = 0;
        int count = 0;
        for (int i = 0; i < n; ++i)
        {
            if (i & 1)
            {
                backOddSum = evenSum - frontEvenSum;
                backEvenSum = oddSum - frontOddSum - nums[i];
            }
            else
            {
                backOddSum = evenSum - frontEvenSum - nums[i];
                backEvenSum = oddSum - frontOddSum;
            }
            if (frontOddSum + backOddSum == frontEvenSum + backEvenSum)
            {
                ++count;
            }
            if (i & 1)
            {
                frontOddSum += nums[i];
            }
            else
            {
                frontEvenSum += nums[i];
            }
        }
        return count;
    }
};